package com.guaju.yueshangLife.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.databinding.ItemTabShortBinding;

public class OrderTab extends LinearLayout {
    private LayoutInflater layoutInflater;
    private ItemTabShortBinding binding;

    public OrderTab(Context context) {
        super(context);
        init();
    }

    public OrderTab(Context context,AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.order_tab_style);
        String string = ta.getString(R.styleable.order_tab_style_tabtitle);
        boolean value = ta.getBoolean(R.styleable.order_tab_style_isselected,false);
        binding.tabText.setText(string);
        if (value){
            setSelected();
        }else {
            setNormal();
        }
    }

    private void init() {
        layoutInflater = LayoutInflater.from(getContext());
        binding = DataBindingUtil.inflate(layoutInflater, R.layout.item_tab_short, null, false);
        addView(binding.getRoot());

    }

    public void setNormal(){
        binding.tabline.setVisibility(View.INVISIBLE);
        binding.tabText.setTextAppearance(getContext(), R.style.order_tab_normal);
    }
    public void setSelected(){
        binding.tabline.setVisibility(View.VISIBLE);
        binding.tabText.setTextAppearance(getContext(), R.style.order_tab_selected);
    }
}
